package com.weme.mine.dialog

import android.content.Context
import android.os.Bundle
import android.text.TextUtils
import android.view.LayoutInflater
import androidx.fragment.app.FragmentActivity
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.gyf.immersionbar.BarHide
import com.gyf.immersionbar.ImmersionBar
import com.weme.common.databinding.DialogEdGenderBinding
import com.weme.mine.R


interface EdGenderDialogListener {
    fun onGenderEntered(gender: Int)
}

class EdGenderDialog(var mContext: FragmentActivity, var content :String) : BottomSheetDialog(mContext, com.weme.common.R.style.TUIBeautyDialogTheme) {
    private var listener: EdGenderDialogListener? = null
    private lateinit var binding: DialogEdGenderBinding
    var gender = 0
    var oldGender = 0

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ImmersionBar.with(mContext).hideBar(BarHide.FLAG_HIDE_NAVIGATION_BAR).init()
        binding = DialogEdGenderBinding.inflate(LayoutInflater.from(context), null, false)
        setContentView(binding.root)

        window?.setWindowAnimations(com.weme.common.R.style.SlideUpAnimation)
        if(TextUtils.equals(content,context.getString(com.example.resources.R.string.male))){
            binding.imMale.alpha = 1f
            binding.imFemale.alpha = 0.2f
            oldGender = 1
        }
        if(TextUtils.equals(content,context.getString(com.example.resources.R.string.female))){
            binding.imFemale.alpha = 1f
            binding.imMale.alpha = 0.2f
            oldGender = 2
        }


        binding.imMale.setOnClickListener {
            binding.imMale.alpha = 1f
            binding.imFemale.alpha = 0.2f
            gender = 1
            binding.smvBtn.alpha = if(oldGender != gender)1f  else 0.2f

        }
        binding.imFemale.setOnClickListener {
            binding.imFemale.alpha = 1f
            binding.imMale.alpha = 0.2f
            gender = 2
            binding.smvBtn.alpha = if(oldGender != gender)1f  else 0.2f
        }

        binding.smvBtn.setOnClickListener {
            if(gender==0||oldGender==gender||binding.smvBtn.alpha != 1F){
                return@setOnClickListener
            }
            listener?.onGenderEntered(gender)
            dismiss()
        }
    }



    fun setEdGenderDialogListener(listener: EdGenderDialogListener) {
        this.listener = listener
    }
}